package routes

import (
	v12 "gin_vue_blog/api/v1"
	"gin_vue_blog/middleware"
	"gin_vue_blog/utils"
	"github.com/gin-gonic/gin"
)

func InitRoutes() {
	r := gin.Default()
	r.Use(middleware.Logger())
	r.Use(middleware.Cors())
	auth := r.Group("/api/v1")
	auth.Use(middleware.JwtToken())
	{
		// 用户模块的路由接口
		auth.PUT("/user/:id", v12.EditUser)                // 编辑用户
		auth.DELETE("/user/:id", v12.DeleteUser)           // 删除用户
		auth.PUT("/user/password/:id", v12.ChangePassword) // 修改密码

		// 分类模块的路由接口
		auth.POST("/category/add", v12.AddCategory)
		auth.PUT("/category/:id", v12.EditCategory)
		auth.DELETE("/category/:id", v12.DeleteCategory)

		// 文章模块的路由接口
		auth.POST("/article/add", v12.AddArt)      // 添加文章
		auth.PUT("/article/:id", v12.EditArt)      // 编辑文章
		auth.DELETE("/article/:id", v12.DeleteArt) // 删除文章

		auth.POST("/upload", v12.Upload)
	}
	r.GET("users", v12.GetUserList)  // 获取用户列表
	r.POST("/user/add", v12.AddUser) // 添加用户
	r.GET("/category/getList", v12.GetCategoryList)
	r.GET("/category/get", v12.GetCategory)
	r.GET("/article/category", v12.GetCateArt) // 获取分类下的文章
	r.GET("/article/getList", v12.GetArtList)  // 获取文章列表
	r.GET("/article/:id", v12.GetArtInfo)      // 获取文章详情
	r.GET("/article/search", v12.SearchArt)    // 搜索文章
	r.POST("/user/login", v12.Login)           // 后台登录

	r.Run(utils.Config_Message.Server.HttpPort)
}
